package com.feri.redromance01.service.impl;

import com.feri.redromance01.dao.VipInfoDao;
import com.feri.redromance01.entity.VipInfo;
import com.feri.redromance01.service.intf.VipInfoService;
import com.feri.redromance01.util.StringUtil;
import com.feri.redromance01.vo.PageBean;
import com.feri.redromance01.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @autor wfl
 * @time 2022/8/29
 */
@Service
public class VipInfoServiceImpl implements VipInfoService {
    @Autowired
    private VipInfoDao dao;
    @Override
    public R add(VipInfo vipInfo) {
        if (dao.add(vipInfo) >0){
            return R.ok();
        }else {
            return R.fail();
        }
    }

    @Override
    public R update(VipInfo vipInfo) {
        if (dao.update(vipInfo)>0){
            return R.ok();
        }else {
            return R.fail();
        }
    }

    @Override
    public R delete(int id) {
        if (dao.delete(id)>0){
            return R.ok();
        }else {
            return R.fail();
        }
    }

    @Override
    public PageBean selectPage(String name, int page, int limit) {
        if(StringUtil.isNotEmpty(name)){
            name="%"+name+"%";
        }
        int start=(page-1)*limit;
        return PageBean.ok(dao.selectCount(name),dao.selectPage(name,start,limit));
    }
}
